package cn.cheln.explorer.ds.scan;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import cn.cheln.explorer.beans.UpdateBean;
import cn.cheln.explorer.config.Config;
import cn.cheln.explorer.ds.MediaArgs;
import cn.cheln.explorer.ds.util.ContentValuesUtil;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MirrManager
{
  public static final String[] COUNTPROJECTION;
  public static final String[] LISTPROJECTION = { "_data", "title", "_size", "date_modified" };
  public Map<String, MirrDetail> memoryImage = new HashMap();

  static
  {
    COUNTPROJECTION = new String[] { "_id", "_data", "_size", "date_modified", "sort_key" };
  }

  public MirrManager()
  {
    this.memoryImage.put("image", new MirrDetail(MediaArgs.ImageUri));
    this.memoryImage.put("audio", new MirrDetail(MediaArgs.AudioUri));
    this.memoryImage.put("video", new MirrDetail(MediaArgs.VideoUri));
    this.memoryImage.put("apk", new MirrDetail(MediaArgs.otherUri));
    this.memoryImage.put("doc", new MirrDetail(MediaArgs.otherUri));
    this.memoryImage.put("folder", new MirrDetail(MediaArgs.dirUri));
    this.memoryImage.put("lewa/theme", new MirrDetail(MediaArgs.otherUri));
  }

  public static void delete(Context paramContext, Uri paramUri, int paramInt)
  {
    try
    {
      ContentResolver localContentResolver = paramContext.getContentResolver();
      String[] arrayOfString = new String[1];
      arrayOfString[0] = paramInt;
      localContentResolver.delete(paramUri, "_id = ?", arrayOfString);
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public static boolean doDBSync(File paramFile, Uri paramUri, Context paramContext, boolean paramBoolean, UpdateBean paramUpdateBean, String paramString)
  {
    if (paramUpdateBean == null);
    for (Integer localInteger = null; ; localInteger = paramUpdateBean.id)
      return doDBSync(paramFile, paramUri, paramContext, paramBoolean, localInteger, paramString);
  }

  public static boolean doDBSync(File paramFile, Uri paramUri, Context paramContext, boolean paramBoolean, Integer paramInteger, String paramString)
  {
    if (paramBoolean)
    {
      ContentResolver localContentResolver = paramContext.getContentResolver();
      ContentValues localContentValues = ContentValuesUtil.constructContentValues(paramFile, paramString);
      String[] arrayOfString = new String[1];
      arrayOfString[0] = paramInteger;
      if (localContentResolver.update(paramUri, localContentValues, "_id = ?", arrayOfString) <= 0);
    }
    do
    {
      return true;
      return false;
    }
    while (paramContext.getContentResolver().insert(paramUri, ContentValuesUtil.constructContentValues(paramFile, paramString)) != null);
    return false;
  }

  public static Cursor lookForImageMediaFiles(Context paramContext, Uri paramUri, String paramString1, String paramString2, String paramString3, String[] paramArrayOfString)
  {
    String[] arrayOfString1;
    monitorenter;
    try
    {
      ContentResolver localContentResolver = paramContext.getContentResolver();
      if (paramArrayOfString != null)
      {
        arrayOfString1 = paramArrayOfString;
        String str = "mime_type like ? and _size > " + (1024.0F * Config.image_filter_size.floatValue());
        String[] arrayOfString2 = new String[1];
        arrayOfString2[0] = paramString1 + "%";
        Cursor localCursor = localContentResolver.query(paramUri, arrayOfString1, str, arrayOfString2, paramString2);
        return localCursor;
      }
    }
    finally
    {
      monitorexit;
    }
  }

  public static Cursor lookForMediaFiles(Context paramContext, Uri paramUri, String paramString1, String paramString2, String[] paramArrayOfString)
  {
    monitorenter;
    try
    {
      ContentResolver localContentResolver = paramContext.getContentResolver();
      String[] arrayOfString = new String[1];
      arrayOfString[0] = paramString1.toLowerCase() + "%";
      Cursor localCursor = localContentResolver.query(paramUri, paramArrayOfString, "mime_type like ? ", arrayOfString, paramString2);
      monitorexit;
      return localCursor;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public void clearNoUseData(Context paramContext)
  {
    Iterator localIterator1 = this.memoryImage.values().iterator();
    if (!(localIterator1.hasNext()))
      return;
    MirrDetail localMirrDetail = (MirrDetail)localIterator1.next();
    Iterator localIterator2 = localMirrDetail.errorRecords.keySet().iterator();
    while (true)
    {
      if (!(localIterator2.hasNext()))
      {
        Iterator localIterator3 = localMirrDetail.records.values().iterator();
        while (true)
        {
          if (localIterator3.hasNext());
          UpdateBean localUpdateBean2 = (UpdateBean)localIterator3.next();
          delete(paramContext, localMirrDetail.operUri, localUpdateBean2.id.intValue());
        }
      }
      UpdateBean localUpdateBean1 = (UpdateBean)localIterator2.next();
      delete(paramContext, localMirrDetail.operUri, localUpdateBean1.id.intValue());
    }
  }

  public void getContentInjected(Cursor paramCursor, MirrDetail paramMirrDetail)
  {
    if (paramCursor == null)
      return;
    try
    {
      String str1;
      UpdateBean localUpdateBean;
      do
      {
        str1 = paramCursor.getString(paramCursor.getColumnIndex("_data"));
        Integer localInteger = Integer.valueOf(paramCursor.getInt(paramCursor.getColumnIndex("_id")));
        String str2 = paramCursor.getString(paramCursor.getColumnIndex("sort_key"));
        localUpdateBean = new UpdateBean(localInteger, str1, paramCursor.getString(paramCursor.getColumnIndex("_size")), paramCursor.getString(paramCursor.getColumnIndex("date_modified")), str2, null);
        if ((str1 != null) && (!("".equals(str1.trim()))))
          break label148;
        paramMirrDetail.errorRecords.put(localUpdateBean, str1);
      }
      while (paramCursor.moveToNext());
      paramCursor.close();
      return;
      label148: paramMirrDetail.records.put(str1, localUpdateBean);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public Map<String, MirrDetail> getMemoryImage()
  {
    return this.memoryImage;
  }

  public Cursor queryFolderImage(Context paramContext, Uri paramUri)
  {
    return paramContext.getContentResolver().query(paramUri, new String[] { "_data,_id,title from files where format=12289 order by _data asc --" }, null, null, null);
  }

  public Cursor queryImage(Context paramContext, Uri paramUri)
  {
    return paramContext.getContentResolver().query(paramUri, new String[] { "_data", "_id" }, null, null, "_data asc");
  }

  public Cursor queryOthersMirror(Context paramContext, Uri paramUri, String paramString)
  {
    monitorenter;
    try
    {
      Cursor localCursor = paramContext.getContentResolver().query(paramUri, COUNTPROJECTION, paramString, null, "_data asc");
      monitorexit;
      return localCursor;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public void receiveDBImage(Context paramContext, String paramString)
  {
    if ((paramString == null) || (paramString.equals("doc")))
      getContentInjected(queryOthersMirror(paramContext, MediaArgs.otherUri, "mime_type is not null and (mime_type not like 'application/vnd.shortcut.package-archive' and mime_type like 'application%' ) or mime_type like 'text%' and  format  <> 12289"), (MirrDetail)this.memoryImage.get("doc"));
    if ((paramString == null) || (paramString.equals("apk")))
      getContentInjected(queryOthersMirror(paramContext, MediaArgs.otherUri, "format=12288 and lower(_data) like '%.apk' "), (MirrDetail)this.memoryImage.get("apk"));
    if ((paramString == null) || (paramString.equals("folder")))
      getContentInjected(queryOthersMirror(paramContext, MediaArgs.dirUri, "format=12289"), (MirrDetail)this.memoryImage.get("folder"));
    if (paramString != null);
    try
    {
      if (paramString.equals("image"))
        getContentInjected(lookForMediaFiles(paramContext, MediaArgs.ImageUri, "image", "_data asc", COUNTPROJECTION), (MirrDetail)this.memoryImage.get("image"));
      if ((paramString == null) || (paramString.equals("audio")))
        getContentInjected(lookForMediaFiles(paramContext, MediaArgs.AudioUri, "audio", "_data asc", COUNTPROJECTION), (MirrDetail)this.memoryImage.get("audio"));
      if ((paramString == null) || (paramString.equals("video")))
        getContentInjected(lookForMediaFiles(paramContext, MediaArgs.VideoUri, "video", "_data asc", COUNTPROJECTION), (MirrDetail)this.memoryImage.get("video"));
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.explorer.ds.scan.MirrManager
 * JD-Core Version:    0.5.2
 */